<div>
    <ol class="breadcrumb" >
        <li> <i class="fa fa-anchor"></i>
            &nbsp;预约管理
        </li>
        <li>预约订单列表</li>
    </ol>
    <div class="panel ">
        <div class="panel-heading" >
            <i class="fa fa-list"></i>
            &nbsp;&nbsp;预约状态
        </div>
        <form class="search-form" action={:U("Bespeak/index")} method="get">
            <div class="panel-body search-panel-body"  >
                <div class="col-xs-6" style=" width:405px;">
                    <div class="input-group">
                        <span class="input-group-addon" style="width:80px;">所在地</span>
                        <select id="location-f" name="location_f_1" class="form-control" style="width:139px;">
                            <option value="0">--</option>
                            <volist name="china" id="vo">
                                <option value="{$vo.code}">{$vo.name}</option>
                            </volist>
                        </select>

                        <select id="location-s" name="location_s_1" class="form-control" style="width:125px;border-left:0">
                            <option value="0">--</option>
                            <volist name="china" id="vo">
                                <volist name="vo['area']" id="vovo">
                                    <option value="{$vovo.code}" class="{$vo.code}" >{$vovo.name}</option>
                                </volist>
                            </volist>
                        </select>
                    </div>
                </div>
                <div class="col-xs-3 search-col">
                    <div class="input-group">
                        <span class="input-group-addon">设备地址</span>
                        <input type="text" name="key_link" class="form-control" value="{$_GET['key_link']}" placeholder="设备地址"></div>
                </div>
                <div class="col-xs-2 search-col">&nbsp;
                    <button  type="submit" class="btn btn-warning">
                        <i class="fa fa-search"></i>
                        &nbsp;搜索
                    </button>
                </div>
            </div>
        </form>
        <table  class="table table-bordered table-striped table-mcit" >
            <thead>
                <tr>
                    <th>
                        <button class="btn btn-block btn-mcit" type="submit" name="" value="">选择</button>
                    </th>
                    <th >
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>ID</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>站点名称</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>所在区域</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>运营二维码</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>设备地址</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>开始时间</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>用户</button>
                    </th>
                    <th>
                        <button class="btn btn-block btn-mcit" type="submit" name="" value="">在线情况</button>
                    </th>
                    <th>
                        <button class='btn btn-block btn-mcit' type='submit' name='' value=''>操作</button>
                    </th>
                </tr>
            </thead>
            <tbody id="DataTableContent">
                <empty name="charState">
                    <td colspan="99" style="text-align:center" class="danger"> <strong><i class="fa fa-meh-o"></i>
                        &nbsp;&nbsp;当前条件下没有数据</strong>
                    </td>
                <else />
                    <volist name="charState" id="data">
                        <tr class="lists" align="center">
                            <td>
                                <input type="checkbox" data-id="{$data.s_key_link}" data-nid="{$data.evc_number}" data-code="{$data.now_user}" value="{$data.id}"/>
                            </td>
                            <td>{$data.id}</td>
                            <td><span title="{$data.name}">{$data.name_text}</span></td>
                            <td>{$data.location}</td>
                            <td>{$data.evc_number}</td>
                            <td>{$data.key_link}</td>
                            <td>{$data.btime}</td>
                            <td>{$data.now_user}</td>
                            <td>{$data.status}</td>
                            <td>
                                <a class="btn btn-success btn-sm" href="__URL__/detail/id/{$data.id}">
                                    <i class="fa fa-eye"></i>
                                    &nbsp;查看
                                </a>
                                <a class="btn btn-warning btn-sm changehh"  data-value="消约" data-nid="{$data.evc_number}" data-text="{$data.now_user}"  data-id="{$data.s_key_link}" data-info="确定取消预约吗？">
                                    <i class="fa fa-circle"></i>
                                    &nbsp;消约
                                </a>
                            </td>
                        </tr>
                    </volist>
                </empty>
            <tr>
                <td colspan="99">
                    <input type="button" value="全选"   class="btn selectAll">
                    <input type="button" value="全不选" class="btn unSelect" >
                    <input type="button" value="反选"   class="btn reverse" >
                    <input type="button" value="消约" class="btn cancelValues btn-warning" >
                </td>
            </tr>
                <tr>
                    <td colspan="99" style="text-align:center">
                        <ul class="pagination">{$pageView}</ul>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<import file="js.jquery#chained" />
<import file="js.jQuery#md5" />
<script type="text/javascript">
    function getRandomNum(Min,Max)
    {
        var Range = Max - Min;
        var Rand = Math.random();
        var ss = Min + Math.round(Rand * Range);
        return(Min + Math.round(Rand * Range));
    }

    function getToken(hao,randomKey)
    {
        var one = hao.substr(0, 4);
        var two = hao.substr(4,12);
        one = $.md5(one);
        two = $.md5(two);

        //var randomKey=getRandomNum(1,10);
        var result = one + randomKey + two;
        result = $.md5(result);
        return (result);

    }
</script>
<script type="text/javascript">
    $(document).ready(function () {

        $("#location-s").chained("#location-f");
        //全选
        $(".selectAll").click(function () {
            $(".lists :checkbox").prop("checked", true);
        });
        //全不选
        $(".unSelect").click(function () {
            $(".lists :checkbox").prop("checked", false);
        });
        //反选
        $(".reverse").click(function () {
            $(".lists :checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        });
        //取消预约
        $(document).on("click",'.changehh',function(){
            var obj           = $(this).parent();
            var stateKey      = $(this).attr("data-id");//s_key_link
            var evNumber      = $(this).attr("data-nid");//运营二维码
            var user_card     = $(this).attr("data-code");//会员卡号
            var info          = $(this).attr("data-info");//提示内容
            var value         = $(this).attr("data-value");//执行状态
            var url         = "http://id.dz.tt/listen/send8089_v3.php?";
            var code        = "9301";
            var now_user    = "";
            var sendData    = '';
            if(value == "消约"){
                if(user_card != 0 || user_card != ''){
                    now_user  = user_card;
                }else{
                    now_user  = "01234567890123456789";
                }
                var key      = getRandomNum(10,99);
                var token    = getToken(evNumber,key);
                sendData     = 'code='+code+'&key='+key+'&userCard='+now_user+'&token='+token+'&evCharNumber='+evNumber;
            }
            alertify.confirm(info, function (e) {
                if (e) {
                    $.get(url+sendData);
                    //location.reload();
                } else {
                    alertify.error("取消操作！");
                }
            }, "mcit_default");
        });
        //批量取消预约命令
        $(".cancelValues").click(function(){
            var valArr = new Array;
            $("input[type='checkbox']:checked").prop("checked", function(i) {
                valArr[i] = $(this).attr("data-id");
            });
            var vals = valArr.join(',');
            if(vals == ''){
                alert("请选择要处理的选项!");
            }else{
                alertify.confirm("确定处理吗？", function (e) {
                    if (e) {
                        var url         = "http://id.dz.tt/listen/send8089_v3.php?";
                        var code        = "9301";
                        var now_user    = "";
                        var sendData    = '';
                        $("input[type='checkbox']:checked").prop("checked", function(i) {
                            var sklink    = $(this).attr("data-id");//设备地址
                            var evNumber  = $(this).attr("data-nid");//运营二维码
                            var user_card = $(this).attr("data-code");//会员卡号
                            if(user_card != 0 || user_card != ''){
                                now_user  = user_card;
                            }else{
                                now_user  = "01234567890123456789";
                            }
                            var key      = getRandomNum(10,99);
                            var token    = getToken(evNumber,key);
                            sendData     = 'code='+code+'&key='+key+'&userCard='+now_user+'&token='+token+'&evCharNumber='+evNumber;
                            $.get(url+sendData);
                        });
                    } else {
                        alertify.error("取消操作！");
                    }
                }, "mcit_default");
            }
        });
    })
</script>